/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            shopVipLevelInfo: {
                shopVipLevels: [],
                total: 0,
                records: 1,
                moreCondition: false,
                componentShow: 'shopVipLevelInfo',
                vipLevelId: '',
                vipLevels: [],
                conditions: {
                    levelName: '',
                    vipLevel: '',
                    vipLevelId: '',
                    shopId: ''
                }
            }
        },
        _initMethod: function () {
            $that._listShopVipLevels(DEFAULT_PAGE, DEFAULT_ROWS);
            vc.getDict('s_shop_vip_level', "vip_level", function (_data) {
                $that.shopVipLevelInfo.vipLevels = _data;
            });
        },
        _initEvent: function () {
            vc.on('shopVipLevel', 'listShopVipLevel', function (_param) {
                $that.shopVipLevelInfo.componentShow = 'shopVipLevelInfo';
                $that._listShopVipLevels(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('pagination', 'page_event', function (_currentPage) {
                $that._listShopVipLevels(_currentPage, DEFAULT_ROWS);
            });
        },
        methods: {
            _listShopVipLevels: function (_page, _rows) {
                $that.shopVipLevelInfo.conditions.page = _page;
                $that.shopVipLevelInfo.conditions.row = _rows;
                $that.shopVipLevelInfo.conditions.shopId = vc.getCurrentCommunity().shopId;
                
                let param = {
                    params: $that.shopVipLevelInfo.conditions
                };
                param.params.levelName = param.params.levelName.trim();
                param.params.vipLevelId = param.params.vipLevelId.trim();
                //发送get请求
                vc.http.apiGet('/shopVipUser.queryShopVipLevel',
                    param,
                    function (json, res) {
                        let _json = JSON.parse(json);
                        $that.shopVipLevelInfo.total = _json.total;
                        $that.shopVipLevelInfo.records = _json.records;
                        $that.shopVipLevelInfo.shopVipLevels = _json.data;
                        vc.emit('pagination', 'init', {
                            total: $that.shopVipLevelInfo.records,
                            dataCount: $that.shopVipLevelInfo.total,
                            currentPage: _page
                        });
                    }, function (errInfo, error) {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddShopVipLevelModal: function () {
                $that.shopVipLevelInfo.componentShow = 'addShopVipLevel';
                vc.emit('addShopVipLevel', 'openAddShopVipLevelModal', {});
            },
            _openEditShopVipLevelModel: function (_shopVipLevel) {
                $that.shopVipLevelInfo.componentShow = 'editShopVipLevel';
                vc.emit('editShopVipLevel', 'openEditShopVipLevelModal', _shopVipLevel);
            },
            _openDeleteShopVipLevelModel: function (_shopVipLevel) {
                vc.emit('deleteShopVipLevel', 'openDeleteShopVipLevelModal', _shopVipLevel);
            },
            //查询
            _queryShopVipLevelMethod: function () {
                $that._listShopVipLevels(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            //重置
            _resetShopVipLevelMethod: function () {
                $that.shopVipLevelInfo.conditions.levelName = "";
                $that.shopVipLevelInfo.conditions.vipLevel = "";
                $that.shopVipLevelInfo.conditions.vipLevelId = "";
                $that._listShopVipLevels(DEFAULT_PAGE, DEFAULT_ROWS);
            },
            _moreCondition: function () {
                if ($that.shopVipLevelInfo.moreCondition) {
                    $that.shopVipLevelInfo.moreCondition = false;
                } else {
                    $that.shopVipLevelInfo.moreCondition = true;
                }
            }
        }
    });
})(window.vc);
